#!/usr/bin/python
# coding=utf-8
from flask import json
from public import verification, config, date, ran, encryp
from public.http import POST

url = config.domain + '/ja/v1/user/login'
url_auto = config.domain + '/ja/v1/user/login'

login_values = {"name":"17744444443","password":"qwer1234"}


def authkey():
    datajson = json.loads(POST(url, login_values))
    data = datajson["authkey"]
    return data


# 正常登陆错误
def login_common():
    datajson = json.loads(POST(url, login_values))
    ret = datajson["ret"]
    return ret


# 缺少参数
def login_common_1():
    new_values = login_values.copy()
    del new_values["password"]
    datajson = json.loads(POST(url, new_values))
    ret = datajson["ret"]
    return ret



# 密码错误
def login_common_2():
    new_values = login_values.copy()
    new_values["pwd"] = "错误的密码"
    datajson = json.loads(POST(url, new_values))
    ret = datajson["ret"]
    return ret


# 验证码错误
def login_common_3():
    new_values = login_values.copy()
    new_values["ran"] = "验证码错误"
    datajson = json.loads(POST(url, new_values))
    ret = datajson["ret"]
    return ret

# 用户不存在
def login_common_4():
    new_values = login_values.copy()
    new_values["name"] = "15555555555"
    datajson = json.loads(POST(url, new_values))
    ret = datajson["ret"]
    return ret

# 正常自动正常
def login_auto(authkey):
    login_auto_values = {"userid":150650,"language": "zh","authkey":authkey}
    datajson = json.loads(POST(url_auto, login_auto_values))
    ret = datajson["ret"]
    return ret

# 用户不存在自动正常
def login_auto_1(authkey):
    login_auto_values = {"userid":1506501111,"language": "zh","authkey":authkey}
    datajson = json.loads(POST(url_auto, login_auto_values))
    ret = datajson["ret"]
    return ret

# 用户不存在自动正常
def login_auto_2(authkey):
    login_auto_values = {"userid":150650,"authkey":authkey}
    datajson = json.loads(POST(url_auto, login_auto_values))
    ret = datajson["ret"]
    return ret


# 授权码失效
def login_auto_3(authkey):
    login_auto_values =  {"userid":150650,"language": "zh","authkey":authkey}
    datajson = json.loads(POST(url_auto, login_auto_values))
    ret = datajson["ret"]
    return ret

if __name__ == '__main__':
    verification(login_common(),"正常登陆",200)
    verification(login_common_1(),"缺少参数登陆",400)
    verification(login_common_2(),"密码错误登陆",401)
    verification(login_common_3(),"校验码错误登陆",401)
    verification(login_common_4(), "用户不存在登陆", 404)

    authkey = authkey()
    verification(login_auto(authkey),"正常自动登陆",200)
    verification(login_auto_1(authkey),"用户不存在自动登陆",404)
    verification(login_auto_2(authkey),"缺少参数1自动登陆",400)
    verification(login_auto_3("11111111111"),"授权码失效自动登陆",401)

